package com.per.mybootall.test;

import com.alibaba.fastjson.JSON;
import lombok.SneakyThrows;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/4/1
 * Time: 9:39
 * Description:堆栈测试：堆内存对象，栈内存基本数据类型
 */
public class test19 {
  public static void main(String[] args) {
    Map testMap=new HashMap();
    testMap.put("id",1);
    //Map newMap=testMap;//结果：线程1：id:1    线程2：id：3
    Map newMap=new HashMap(){{putAll(testMap);}};//结果：线程1：id:1   线程2：id:3
    System.out.println(JSON.toJSONString(testMap));
    new Thread(new Runnable() {
      @SneakyThrows
      @Override
      public void run() {
        System.out.println("线程1："+JSON.toJSONString(newMap));
      }
    }).start();
    new Thread(new Runnable() {
      @Override
      public void run() {
        testMap.put("id",3);
        System.out.println("线程2："+JSON.toJSONString(newMap));
      }
    }).start();
  }
}
